#!/usr/bin/env bash
#cd ..
#npm run build
#cd brun
#VERSION=0.1
cpath=`pwd`
echo $cpath
PROJECT_PATH=${cpath%src*} #从右向左截取第一个 src 后的字符串
echo ${PROJECT_PATH}


#export GOPATH=$GOPATH:${PROJECT_PATH}

source base.sh

path=`pwd`

echo $path
echo ${path%src*} #从右向左截取第一个 src 后的字符串

#dep ensure -update
rm ${TARGET_NAME}*.zip
rm ${TARGET_NAME}*.tar.gz
rm ${TARGET_NAME}*.run
rm -fr .${TARGET_NAME}
rm ${TARGET_FILE_NAME}*

build(){
   echo $GOOS $GOARCH
   env  GOOS=${GOOS} GOARCH=${GOARCH}  go build -o ${TARGET_FILE_NAME}_${GOOS}_${GOARCH}${EXT} -v ${SOURCE_FILE_NAME}.go
   chmod +x ${TARGET_FILE_NAME}_${GOOS}_${GOARCH}${EXT}
   mv ${TARGET_FILE_NAME}_${GOOS}_${GOARCH}${EXT} ${TARGET_FILE_NAME}${EXT}
   if [ ${GOOS} == "windows" ]; then
       zip ${TARGET_NAME}_${GOOS}_${GOARCH}.zip ${TARGET_FILE_NAME}${EXT} conf.ini  ../dist/
   else
       tar --exclude=*.gz --exclude=*.run --exclude=*.git --exclude=*.go  -czvf ${TARGET_NAME}_${GOOS}_${GOARCH}.tar.gz  ${TARGET_FILE_NAME}${EXT} config.ini  run.sh stop.sh -C ./ .
#       cp install.sh ${TARGET_NAME}_${GOOS}_${GOARCH}.run
#       cat ${TARGET_NAME}_${GOOS}_${GOARCH}.tar.gz >> ${TARGET_NAME}_${GOOS}_${GOARCH}.run
#       chmod +x ${TARGET_NAME}_${GOOS}_${GOARCH}.run
   fi
   mv  ${TARGET_FILE_NAME}${EXT} ${TARGET_FILE_NAME}_${GOOS}_${GOARCH}${EXT}
}

CGO_ENABLED=0
# linux
GOOS=linux
GOARCH=amd64
EXT=
build

# mac osx
GOOS=darwin
GOARCH=amd64
build
# windows
#GOOS=windows
#GOARCH=amd64
#EXT=.exe
#
#build
#
#GOARCH=386
#build

